package codingforgreat.lchot150;

public class Lc108 {
  public class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
  }
    public TreeNode sortedArrayToBST(int[] nums) {
        return func(nums,0,nums.length - 1);
    }
    public TreeNode func(int[] nums,int L,int R){
        if(L > R){
            return null;
        }
        if(L == R){
            return new TreeNode(nums[L]);
        }
        int M = (L + R) /2;
        TreeNode left = func(nums,L,M - 1);
        TreeNode right = func(nums,M + 1,R);
        TreeNode res = new TreeNode(nums[M]);
        res.left = left;
        res.right = right;
        return res;
    }
}
